// pages/tangyouquan/tangyouquan.js
const app = getApp();
var njzxw = require('../../../utils/njzxw.js');
var url = require('../../../utils/url.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
    data: {},
    /**
     * 回复数据
     */
    hf:[
      {
        image: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535826957797&di=a9f0ef340b93c3d3247c3605d67bae73&imgtype=0&src=http%3A%2F%2Fpic3.nipic.com%2F20090708%2F2082016_090748061_2.jpg',
        name: '张三',
        num: '1楼',
        remark: '可以具体讲解',
        time: '2天前',
        dianzhan: '2',
        hf: '2W',
        hfList:[
          {
            id:'2',
            name:'李四',
            hfName:'',
            remark:'有事吧'
          },
          {
            id: '2',
            name: '王五',
            hfName: '李四',
            remark: '有事吧有事吧有事吧有事吧有事吧有事吧有事吧有事吧有事吧有事吧'
          }
        ]
      },
      {
        image: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535826957797&di=a9f0ef340b93c3d3247c3605d67bae73&imgtype=0&src=http%3A%2F%2Fpic3.nipic.com%2F20090708%2F2082016_090748061_2.jpg',
        name: '张三',
        num: '2楼',
        remark: '可以具体讲解',
        time: '2天前',
        dianzhan: '2',
        hf: '2W'
      },
      {
        image: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535826957797&di=a9f0ef340b93c3d3247c3605d67bae73&imgtype=0&src=http%3A%2F%2Fpic3.nipic.com%2F20090708%2F2082016_090748061_2.jpg',
        name: '张三',
        num: '3楼',
        remark: '可以具体讲解',
        time: '2天前',
        dianzhan: '2',
        hf: '2W'
      }
    ]
  },
  /**
   * 删除评论
   */
  deleteCommon:function(e){
    var res_id = njzxw.getDataVal(e,'id');
    var $this = this;
    njzxw.alert({
      msg:'确定删除吗？',
      confirm:true,
      
      fun:function(a){
        
        if(a){
          njzxw.ajax({
            url: url.commeninfo.delete,
            data:{
              ids:[
                res_id
              ]
            },
            load: true,
            fun:function(a,b){
              wx.hideLoading();
              if(a){
                if(b.data.state == 1){
                  njzxw.alert({
                    msg:'操作成功',
                    fun:function(){
                      $this.loadData($this);
                    }
                  });
                  
                } else {
                  njzxw.alert({
                    error: true,
                    msg: '删除失败'
                  });
                }
              }else{
                njzxw.alert({
                  error:true,
                  msg: '操作失败'
                });
              }
            }
          });
        }
      }
    });
  },
  imgYu: function (event) {
    var src = event.currentTarget.dataset.src;//获取data-src
    // var imgList = event.currentTarget.dataset.list;//获取data-list
    console.log(src);
    //图片预览
    wx.previewImage({
      current: src[0], // 当前显示图片的http链接
      urls: src // 需要预览的图片http链接列表
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    });
    njzxw.initFun(this);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadData(this);
  },
  loadData:function($this){
    njzxw.ajax({
      url: url.dynamicInfo.queryId,
      data:{
        id:$this.data.id
      },
      load:true,
      fun:function(a,b){
        if(a){
          var data = b.data.data.list;
          var hf = b.data.data.hfList;
          // console.log(b.data.data.list);
          var path = b.data.data.list.path;
          var paths = [];
          if(path != undefined && path != null && path != ''){
            paths = path.split(',');
          }
          $this.setData({
            data: data,
            hf: hf,
            paths: paths
          });
          // console.log($this.data.paths);
          wx.hideLoading();
        }else{
          njzxw.alert({
            msg:'数据加载错误'
          });
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  dianzhan:function(e){
    var $this = this;
    var id = njzxw.getDataVal(e,'id');
    var type = njzxw.getDataVal(e, 'type');
    njzxw.ajax({
      url: url.dynamicInfo.dianzhan,
      load:true,
      data:{
        id:id,
        type: type
      },
      fun:function(a,b){
        if(a){
          if(b.data.state == 1){
            wx.showToast({
              title: '点赞成功',
            })
            $this.loadData($this);
          }else{
            njzxw.alert({ msg: b.data.msg });
          }
        }else{
          njzxw.alert({msg:'操作失败'});
        }
      }
    });
  },
  /**
   * 显示回复按钮
   */
  showAction:function(e){
    var name = e.currentTarget.dataset.name;
    var param = njzxw.getDataVal(e,'param');
    wx.showActionSheet({
      itemList: ["回复【"+name+"】"],
      success: function (res) {
        wx.navigateTo({
          url: '/pages/tangyouquan/huifu/huifu?' + param,
        })
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    });
    return false;
  }
})